﻿using EMall.ProductService.Categories;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace EMall.ProductService.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CategoryController : ControllerBase
    {
        private readonly ICategoryAppService _categoryAppService;
        public CategoryController(ICategoryAppService categoryAppService)
        {
            _categoryAppService = categoryAppService;
        }
        [HttpPost]
        public async Task CreateAsync(CreateCategoryDto input)
        {
            await _categoryAppService.CreateAsync(input);
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateCategoryDto input)
        {
            await _categoryAppService.UpdateAsync(input);
        }
        [HttpDelete]
        public async Task DeleteAsync(DeleteCategoryDto input)
        {
            await _categoryAppService.DeleteAsync(input);
        }
        [HttpGet]
        public async Task<CategoryDto> GetAsync(int id)
        {
            return await _categoryAppService.GetAsync(id);
        }
        [HttpGet]
        public async Task<IEnumerable<CategoryListDto>> GetListAsync([FromQuery] GetCategoryListQueryDto input)
        {
            return await _categoryAppService.GetListAsync(input);
        }
        [HttpGet]
        public async Task<IPagedList<CategoryListDto>> GetPagedListAsync([FromQuery] GetCategoryListPagingAndSortingQueryDto input)
        {
            return await _categoryAppService.GetPagedListAsync(input);
        }
        [HttpGet]
        public async Task<CategoryTree> GetTreeAsync()
        {
            return await _categoryAppService.GetTreeAsync();
        }
    }
}
